
from datetime import datetime
from typing import Union, Any, Optional, List

from pydantic import BaseModel, EmailStr, Field
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from sqlalchemy.schema import Sequence

#from app.common.database import Base
from app.models.base import TableBase


class Factor(TableBase):
    __tablename__ = "t_factor"

    fid = Column(Integer, primary_key=True, index=True)
    factor_no = Column(String(24), unique=True, index=True, comment='代理编号')
    factor_name = Column(String(40), comment='创建人')
    factor_lvl = Column(Integer, comment='代理级别')
    up_factor_no = Column(String(24), comment='上级代理编号')
    cert_type = Column(String(2), comment='证件类型')
    cert_no = Column(String(30), comment='证件号')
    status = Column(Integer, comment='状态')
    contact_person = Column(String(32), comment='联系人')
    email = Column(String(40), comment='邮箱')
    address = Column(String(120), comment='地址')


class FactorFee(TableBase):
    """代理费率表"""
    __tablename__ = "t_factor_fee_rate"

    id = Column(Integer, primary_key=True, index=True)
    factor_no = Column(String(40), unique=True, index=True, comment='代理编号')
    product_code = Column(String(32), comment='产品编码')
    product_name = Column(String(40), comment='产品名称')
    pay_channel_code = Column(String(32), comment='通道编码')
    fee_mode = Column(Integer, comment='计费模式 1.单笔固定 2.百分比')
    fee_value = Column(Integer, comment='费率值')
    status = Column(Integer, comment='状态')

    __table_args__ = (
        UniqueConstraint('factor_no', 'product_code', 'pay_channel_code', 'fee_mode'),
    )

